<?php

namespace Lib\View\Helper;

use StdClass,
    Lib\Util\Session as SessionMain;

class Session extends SessionMain {

    public static function flash($hide = true) {
        $flash = null;
        $message = SessionMain::read('Flash.message');
        $type    = SessionMain::read('Flash.type');
        if (!empty($message)) {
            $flash = new StdClass;
            $flash->message = $message;
            $flash->type = $type;

            $html = '
                <div id="flash-message">
                    <div class="%s">%s</div>
                </div>
            ';

            if ($hide) {
                $html .= '<script type="text/javascript">
                        $(function(){
                            setTimeout(function(){
                                var el = $(\'#flash-message\');
                                el.animate({
                                    top: -2 * el.height()
                                });
                            }, 3000);
                        });
                    </script>
                ';
            }
            $flash = sprintf($html, $flash->type, $flash->message);
        }

        SessionMain::delete('Flash.message');
        SessionMain::delete('Flash.type');
        return $flash;
    }

}